#include "stdafx.h"
#include <glut.h>

#include "Utility.h"

CUtility::CUtility( )
{
}

CUtility::~CUtility( )
{
}

bool CUtility::UnProjectScreenPosition( const int inPosX, const int inPosY, GLdouble& outPosX, GLdouble& outPosY, GLdouble& outPosZ )
{
	GLint theViewPort[4];
	GLdouble theModelMatrix[16];
	GLdouble theProjectionMatrix[16];
	
	glGetIntegerv( GL_VIEWPORT, theViewPort );
	glGetDoublev( GL_MODELVIEW_MATRIX, theModelMatrix );
	glGetDoublev( GL_PROJECTION_MATRIX, theProjectionMatrix );

	int thePosY = theViewPort[3] - inPosY - 1;

	gluUnProject( ( GLdouble ) inPosX, ( GLdouble ) thePosY, ( GLdouble ) 0, theModelMatrix, theProjectionMatrix, theViewPort, &outPosX, &outPosY, &outPosZ );

	printf( "Unprojection : Pos X = %f Pos Y = %f\n Pos Z = %f\n", outPosX, outPosY, outPosZ );
	return true;
}